package com.hapedu.gegeric.Homework;

import java.util.*;

public class GenericExercise {
    public static void main(String[] args) {
        HashSet<Student> set = new HashSet<Student>();
        set.add(new Student("john",12));
        set.add(new Student("jack",13));
        set.add(new Student("jhon",14));
        Iterator<Student> iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next().getName());
        }

        HashMap<String, Student> hm = new HashMap<>();
        hm.put("tom",new Student("tom",28));
        hm.put("smith",new Student("smith",48));
        hm.put("hsp",new Student("hsp",28));

        System.out.println("===============" +
                "");
        Set<Map.Entry<String, Student>> entries = hm.entrySet();
        Iterator<Map.Entry<String, Student>> iterator1 = entries.iterator();
        while (iterator1.hasNext()){
            Map.Entry<String, Student> next = iterator1.next();
            System.out.println(next.getKey()+"-"+next.getValue());
        }

    }
}
class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
